<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改计划')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-ncPlan-edit" th:object="${ncPlan}">
        <input id="treeId2" name="team" type="hidden"  th:field="*{team}"/>

        <input id="planId" name="planId" th:field="*{planId}" type="hidden">
        <!--计划类型 1：育苗 计划2：生产计划-->
        <input id="planType" name="planType" th:field="*{planType}" type="hidden">
        <input id=" orderId" name="orderId" th:field="*{orderId}" type="hidden">
        <input id="standardId" name="standardId" th:field="*{standardId}" type="hidden">
        <!--作物品种ID-->
        <input id="treeId" name="cropVarieties" th:field="*{cropVarieties}" type="hidden"/>

        <div class="form-group">
            <label class="col-sm-3 control-label">计划编号：</label>
            <div class="col-sm-8">
                <input id="planCode" name="planCode"  th:field="*{planCode}" readonly class="form-control" type="text">
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">作物品种：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" name="cropVarietiesCn" required th:field="*{cropVarietiesCn}"  type="text"  onclick="selectCaiTree()" id="treeName" readonly="true">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">设施类型：</label>
            <div class="col-sm-8">
                <select name="landType" required class="form-control m-b">
                    <option value="1" th:selected="*{landType == '1'}">日光温室</option>
                    <option value="2" th:selected="*{landType == '2'}">春秋棚</option>
                    <option value="3" th:selected="*{landType == '3'}">连栋温室</option>
                    <option value="4" th:selected="*{landType == '4'}">露地</option>
                </select>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label ">生产班组：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectDeptTree()" th:field="*{teamCn}" id="teamCn" name="teamCn" required
                           readonly="true">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">播种/定植时间：</label>
            <div class="col-sm-8">
                <input id="planTime"  data-format="yyyy-MM-dd" required name="planTime" th:value="*{#dates.format(planTime, 'yyyy-MM-dd')}" class="form-control" type="text" th:class="time-input" >
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">茬次：</label>
            <div class="col-sm-8">
                <input id="chaci" name="chaci" required th:field="*{chaci}" class="form-control" type="number" onkeyup=" value=value.replace(/^(0+)|[^\d]+/g,'')">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">单茬面积(亩)：</label>
            <div class="col-sm-8">
                <input id="area" name="area" required th:field="*{area}" class="form-control" step="0.01" type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">间数：</label>
            <div class="col-sm-8">
                <input id="jian" name="jian" required th:field="*{jian}" class="form-control"  type="number" onkeyup=" value=value.replace(/^(0+)|[^\d]+/g,'')">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">总面积(亩)：</label>
            <div class="col-sm-8">
                <input id="sumArea" name="sumArea" required th:field="*{sumArea}" class="form-control" step="0.01" type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">循环面积(亩)：</label>
            <div class="col-sm-8">
                <input id="cycleArea" name="cycleArea" required th:field="*{cycleArea}" class="form-control" step="0.01" type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">循环天数：</label>
            <div class="col-sm-8">
                <input id="cycleDays" name="cycleDays" required th:field="*{cycleDays}" class="form-control" type="number" onkeyup=" value=value.replace(/^(0+)|[^\d]+/g,'')">
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">计划制定时间：</label>
            <div class="col-sm-8">
                <input id="createTime" name="createTime" th:field="*{createTime}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">计划制定人：</label>
            <div class="col-sm-8">
                <input id="createBy" name="createBy" th:field="*{createBy}" class="form-control" type="text">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" rows="4" name="remark" th:field="*{remark}" class="form-control" type="text"></textarea>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "system/ncPlan2";
    var cai_prefix = ctx + "system/cai";
    var dept_prefix = ctx + "system/dept";
    $("#form-ncPlan-edit").validate({
        rules: {
            chaci: {
                required: true,
                number:true,
                digits:true,
                min:0
            },
            cycleDays: {
                required: true,
                number:true,
                digits:true,
                min:0
            },
            area: {
                required: true,
                number:true,
                min:0
            },
            jian: {
                required: true,
                min:0
            },
            cycleArea: {
                required: true,
                number:true,
                min:0
            },
            sumArea: {
                required: true,
                number:true,
                min:0
            },
        },
        messages: {
            chaci: {
                required: "茬次不能为空",
                digits:"请输入正整数"
            },
            sumArea: {
                required: "总面积不能为空",
            },
            cycleDays: {
                required: "循环天数不能为空",
                digits:"请输入正整数"
            },
            area: {
                required: "面积不能为空",
            },
            jian: {
                required: "间数不能为空",
            },
            cycleArea: {
                required: "循环面积不能为空",
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-ncPlan-edit').serialize());
        }
    }


    /*蔬菜管理-新增-选择父蔬菜树*/
    function selectCaiTree() {
        var options = {
            title: '蔬菜选择',
            width: "380",
            url: cai_prefix + "/selectCaiTree/" + $("#treeId").val()+'?parentIds=210,',
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
        }
    }

    /*部门管理-新增-选择父部门树*/
    function selectDeptTree() {
        var options = {
            title: '部门选择',
            width: "380",
            url : ctx + "system/dept/selectDeptTree/" + $("#treeId2").val() + "?level=1&rank=2&"+'parentIds=101,',
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }

    function doSubmit2(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId2").val(body.find('#treeId').val());
            $("#teamCn").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>
